package semantic.rules.walk

import utils.data.CTree
import scala.collection.mutable.Buffer
import semantic.COperations._
import lexis.CLexemeType
import syntax.{CNonTerminal, CTerminal, CGrammar, CASTNode}
import syntax.CGrammar._
import semantic.rules.CRuleException

object CWalkRuleOrAndNot extends CWalkRule
{
    override val categories:Seq[CNonTerminal] = CBooleanOr :: CBooleanAnd :: CBooleanNot :: Nil

    override def post(node:CASTNode)(implicit tree:CTree[CASTNode], code:Buffer[String]) = if (node.children.size > 1) node().secondChild().category.name match
    {
        case CLexemeType.OR.name => code += OR
        case CLexemeType.AND.name => code += AND
        case nm =>
            if (node.category == CBooleanNot) code += NOT
            else CRuleException(CRuleException.WRONG_NODE_TYPE(nm))
    }
}
